package com.hubiwei.gmall.realtime.util;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.HashSet;
import java.util.Set;

public class IkUtil {
    // TODO
    public static Set<String> split(String keyword) {
        // 内存流:
        HashSet<String> words = new HashSet<>();
        // 字符串    内存流    字符输入流
        StringReader reader = new StringReader(keyword);
        IKSegmenter seg = new IKSegmenter(reader, true);
        try {
            Lexeme next = seg.next();
            while (next != null) {
                String word = next.getLexemeText();
                words.add(word);
                next = seg.next();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    
        return words;
    }
    
    public static void main(String[] args) {
        System.out.println(split("我是中国人"));
    }
}
